package com.nju.edu.android_app;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import com.nju.edu.android_app.callback.CommentListener;
import com.weibo.sdk.android.api.CommentsAPI;
import com.weibo.sdk.android.demo.R;
import com.weibo.sdk.android.demo.R.layout;
import com.weibo.sdk.android.demo.R.menu;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class CommentActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_comment);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.comment, menu);
		return true;
	}

	public void back(View v){
		this.finish();
	}
	
	public void publish(View v){
		Intent i=this.getIntent();
		long id=i.getLongExtra("id", 0);
		EditText et=(EditText)findViewById(R.id.edit_comment);
		String str=et.getText().toString();
		if(str.equals("")){
			Toast.makeText(CommentActivity.this, "内容不能为空", Toast.LENGTH_SHORT).show();
			return;
		}
		try {
			String comments = URLEncoder.encode(str, "UTF-8");
			CommentsAPI commentsApi=new CommentsAPI(MainActivity.accessToken);
			commentsApi.create(str, id, false, new CommentListener(this));
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public Handler handler=new Handler(){
		@Override
		public void handleMessage(Message msg) {
			Toast.makeText(CommentActivity.this, "评论成功", Toast.LENGTH_SHORT).show();
		}
	};
}
